package org.toools.gwt.demo.jpa;

import java.util.Collection;
import java.util.Vector;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import net.sf.gilead.pojo.java5.LightEntity;

/**
 *
 * @author stefan asseg
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Application.getAll", query = "SELECT a FROM Application a"),
    @NamedQuery(name = "Application.getById", query = "SELECT a FROM Application a WHERE a.id = :id"),
    @NamedQuery(name = "Application.getByContent", query = "SELECT a FROM Application a WHERE a.content = :content")
})
public class Application extends LightEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
    private String content;
    @ManyToMany
    private Collection<CompanyPart> companyParts = new Vector<CompanyPart>();

    public Application() {
    }

    public Application(String content) {
        this.content = content;
    }

    public Application(String content, Collection<CompanyPart> companyParts) {
        this.content = content;
        this.companyParts = companyParts;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Collection<CompanyPart> getCompanyParts() {
        return companyParts;
    }

    public void setCompanyParts(Collection<CompanyPart> companyParts) {
        this.companyParts = companyParts;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Application)) {
            return false;
        }
        Application other = (Application) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Application [id = " + id + "] [content = " + content + "]";
    }
}
